
function loadFriends() 
{	
	var params = {};
	params[opensocial.DataRequest.PeopleRequestFields.MAX] = 5000;	
	  var req = opensocial.newDataRequest();	
		req.add(req.newFetchPeopleRequest(opensocial.DataRequest.Group.VIEWER_FRIENDS,params), 'viewer_friends');
	  req.send(onLoadFriends);
}

function onLoadFriends(data) {  
  var friends = new Array();  
  var viewerFriends = data.get('viewer_friends').getData();
  html = new Array();
  html.push('<select id="person">');
  viewerFriends.each(function(person) {
    html.push('<option value="' + person.getId() + '">' + person.getDisplayName() + "</option>");
    
    friends[person.getId()] = person.getDisplayName();
  });
  html.push('</select>');
  document.getElementById('friends').innerHTML = html.join('');  
}

function requestSendMessage(){
	
	var recipient = document.getElementById('person').value;
	 
	var params = {};
	params[opensocial.Message.Field.TITLE]="Hello";
	var body="Please Check This Application.";   
	var message = opensocial.newMessage(body, params);
	
	opensocial.requestSendMessage(recipient, message);
}

 function create_unique_random_array(num_elements,min,max) 
 {
		var temp, nums = new Array;
		for (var element=0; element < num_elements; element++) 
		{
			while ((temp = number_found ( random_number ( min, max ), nums )) == -1 )
			{
			}
			nums[element] = temp;
		}
		return (nums);
}
function number_found (random_number,number_array) 
{
		for (var element=0; element < number_array.length; element++) 
		{
			if (random_number == number_array[element]) 
			{
				return ( -1 );
			}
		}
		return ( random_number );
}
function random_number(min,max) 
{
    return (Math.round((max-min) * Math.random() + min));
}


 function postActivity(text) {  
    var params = {};  
    params[opensocial.Activity.Field.TITLE] = text;
    var activity = opensocial.newActivity(params); 
    opensocial.requestCreateActivity(activity, opensocial.CreateActivityPriority.HIGH,callback);
  };   
  
  function callback(status) {
    if (status.hadError())
    {
     // alert("Error creating activity.");
    }
    else 
    {
     // alert("Activity successfully created.");
    }
  };

   
  function populateMyAppData() {
	
	var prefs = new gadgets.Prefs();
	
	var div = document.getElementById('content_div');
	div.innerHTML = "";
	var htmlout = "";
	var table1html = "";
	var table2html = "";
htmlout += "<table style='background-color:#FFF;font-family:Verdana, Arial, Helvetica, sans-serif;' cellpadding='0' cellspacing='0' width='100%'>";
   htmlout +="<tr><td colspan='2'><b>Quiz Questions</b>&nbsp;&nbsp;<input type='button' class='buttonAdd' name='btnReload' id='btnReload' value='Reload Quiz' onclick='init()' /></td></tr>";
   htmlout +="<tr><td colspan='2' style='height:10px;'></td></tr>";
   
    table1html += "<table style='background-color:#FFF;font-family:Verdana, Arial, Helvetica, sans-serif;' cellpadding='0' cellspacing='0' width='100%'>"
	 table2html += "<table style='background-color:#FFF;margin-left:25px;font-family:Verdana, Arial, Helvetica, sans-serif;' cellpadding='0' cellspacing='0' width='100%'>"
   
   var me = null;
   
   var myNumArray = create_unique_random_array( 10, 1, 20 );
   var data1 = "<div style='width:100%;background-color:#59a9c3;color:#FFFFFF;padding-left:10px;font-size:11px;padding-top:2px;padding-bottom:2px;'>"+prefs.getMsg("Who was the first Muslim President of India?")+"</div>";
	data1 += "<input type='radio' name='data1' value='0' />"+prefs.getMsg("Dr.Abdul Kalam")+"<br />";
    data1 += "<input type='radio' name='data1' value='5' />"+prefs.getMsg("Zakir Hussain")+"<br />";
    data1 += "<input type='radio' name='data1' value='0' />"+prefs.getMsg("Dr.Fakhruddin Ali Ahmed")+"<br />";
	data1 += "<br />";
   // htmlout += data1+ "<br />";
	
	var data2 = "<div style='width:100%;background-color:#59a9c3;color:#FFFFFF;padding-left:10px;font-size:11px;padding-top:2px;padding-bottom:2px;'>"+prefs.getMsg("Which cricketer holds the world record of maximum number of sixes in Tests?")+"</div>";
	data2 += "<input type='radio' name='data2' value='0' />"+prefs.getMsg("Chris Cairns")+"<br />";
    data2 += "<input type='radio' name='data2' value='5' />"+prefs.getMsg("Sachin Tendulkar")+"<br />";
    data2 += "<input type='radio' name='data2' value='0' />"+prefs.getMsg("Sanath Jayasuriya")+"<br />";
	data2 += "<br />";
	//htmlout += data2+ "<br />";
	
	var data3 = "<div style='width:100%;background-color:#59a9c3;color:#FFFFFF;padding-left:10px;font-size:11px;padding-top:2px;padding-bottom:2px;'>"+prefs.getMsg("Which country was readmitted to the Commonwealth recently?")+"</div>";
	data3 += "<input type='radio' name='data3' value='0' />"+prefs.getMsg("Ghana")+"<br />";
    data3 += "<input type='radio' name='data3' value='5' />"+prefs.getMsg("Pakistan")+"<br />";
    data3 += "<input type='radio' name='data3' value='0' />"+prefs.getMsg("Serbia and Montenegro")+"<br />";
	data3 += "<br />";
	//htmlout += data3+ "<br />";
	
	var data4 = "<div style='width:100%;background-color:#59a9c3;color:#FFFFFF;padding-left:10px;font-size:11px;padding-top:2px;padding-bottom:2px;'>"+prefs.getMsg("Which is the highest waterfall in the world?")+"</div>";
	data4 += "<input type='radio' name='data4' value='0' />"+prefs.getMsg("Salto Angel Falls")+"<br />";
    data4 += "<input type='radio' name='data4' value='5' />"+prefs.getMsg("Niagara Falls")+"<br />";
    data4 += "<input type='radio' name='data4' value='0' />"+prefs.getMsg("Elephanta falls")+"<br />";
	data4 += "<br />";
	//htmlout += data4+ "<br />";

	var data5 = "<div style='width:100%;background-color:#59a9c3;color:#FFFFFF;padding-left:10px;font-size:11px;padding-top:2px;padding-bottom:2px;'>"+prefs.getMsg("Which is the birthplace of Lord Buddha?")+"</div>";
	data5 += "<input type='radio' name='data5' value='0' />"+prefs.getMsg("India")+"<br />";
    data5 += "<input type='radio' name='data5' value='5' />"+prefs.getMsg("China")+"<br />";
    data5 += "<input type='radio' name='data5' value='0' />"+prefs.getMsg("Nepal")+"<br />";
	data5 += "<br />";
	//htmlout += data5+ "<br />";

	var data6 = "<div style='width:100%;background-color:#59a9c3;color:#FFFFFF;padding-left:10px;font-size:11px;padding-top:2px;padding-bottom:2px;'>"+prefs.getMsg("Which is the largest planet in solar system?")+"</div>";
	data6 += "<input type='radio' name='data6' value='0' />"+prefs.getMsg("Saturn")+"<br />";
    data6 += "<input type='radio' name='data6' value='5' />"+prefs.getMsg("Mars")+"<br />";
    data6 += "<input type='radio' name='data6' value='0' />"+prefs.getMsg("Jupiter")+"<br /><br />";
	//htmlout += data6+ "<br />";
	
	var data7 = "<div style='width:100%;background-color:#59a9c3;color:#FFFFFF;padding-left:10px;font-size:11px;padding-top:2px;padding-bottom:2px;'>"+prefs.getMsg("Which of these was once the national drink of Scotland?")+"</div>";
	data7 += "<input type='radio' name='data7' value='0' />"+prefs.getMsg("Claret")+"<br />";
    data7 += "<input type='radio' name='data7' value='5' />"+prefs.getMsg("Amaretto")+"<br />";
    data7 += "<input type='radio' name='data7' value='0' />"+prefs.getMsg("Vodka")+"<br /><br />";
	//htmlout += data6+ "<br />";
	
	var data8 = "<div style='width:100%;background-color:#59a9c3;color:#FFFFFF;padding-left:10px;font-size:11px;padding-top:2px;padding-bottom:2px;'>"+prefs.getMsg("According to the International Cloud Atlas, which of these is the highest?")+"</div>";
	data8 += "<input type='radio' name='data8' value='0' />"+prefs.getMsg("Cloud nine")+"<br />";
    data8 += "<input type='radio' name='data8' value='5' />"+prefs.getMsg("Cloud zero")+"<br />";
    data8 += "<input type='radio' name='data8' value='0' />"+prefs.getMsg("Fog")+"<br /><br />";
	//htmlout += data6+ "<br />";
	
	var data9 = "<div style='width:100%;background-color:#59a9c3;color:#FFFFFF;padding-left:10px;font-size:11px;padding-top:2px;padding-bottom:2px;'>"+prefs.getMsg("Which is the deepest loch in Scotland?")+"</div>";
	data9 += "<input type='radio' name='data9' value='0' />"+prefs.getMsg("Loch Lomand")+"<br />";
    data9 += "<input type='radio' name='data9' value='5' />"+prefs.getMsg("Loch Ness")+"<br />";
    data9 += "<input type='radio' name='data9' value='5' />"+prefs.getMsg("Loch Morar")+"<br /><br />";
	//htmlout += data6+ "<br />";
	
	var data10 = "<div style='width:100%;background-color:#59a9c3;color:#FFFFFF;padding-left:10px;font-size:11px;padding-top:2px;padding-bottom:2px;'>"+prefs.getMsg("What was the first of Earth's supercontinents?")+"</div>";
	data10 += "<input type='radio' name='data10' value='0' />"+prefs.getMsg("Pangaea")+"<br />";
    data10 += "<input type='radio' name='data10' value='5' />"+prefs.getMsg("Gondwanaland")+"<br />";
    data10 += "<input type='radio' name='data10' value='0' />"+prefs.getMsg("Rodinia")+"<br /><br />";
	//htmlout += data6+ "<br />";
	
	var data11 = "<div style='width:100%;background-color:#59a9c3;color:#FFFFFF;padding-left:10px;font-size:11px;padding-top:2px;padding-bottom:2px;'>"+prefs.getMsg("In which country was the Can-Can invented?")+"</div>";
	data11 += "<input type='radio' name='data11' value='0' />"+prefs.getMsg("France")+"<br />";
    data11 += "<input type='radio' name='data11' value='5' />"+prefs.getMsg("UK")+"<br />";
    data11 += "<input type='radio' name='data11' value='0' />"+prefs.getMsg("Canada")+"<br /><br />";
	//htmlout += data6+ "<br />";
	
	var data12 = "<div style='width:100%;background-color:#59a9c3;color:#FFFFFF;padding-left:10px;font-size:11px;padding-top:2px;padding-bottom:2px;'>"+prefs.getMsg("The word 'absinthe' comes from the Greek apsinthion, meaning what?")+"</div>";
	data12 += "<input type='radio' name='data12' value='0' />"+prefs.getMsg("Green Monster")+"<br />";
    data12 += "<input type='radio' name='data12' value='5' />"+prefs.getMsg("Vomiting")+"<br />";
    data12 += "<input type='radio' name='data12' value='0' />"+prefs.getMsg("Undrinkable")+"<br /><br />";
	//htmlout += data6+ "<br />";
	
	var data13 = "<div style='width:100%;background-color:#59a9c3;color:#FFFFFF;padding-left:10px;font-size:11px;padding-top:2px;padding-bottom:2px;'>"+prefs.getMsg("A swede is?")+"</div>";
	data13 += "<input type='radio' name='data13' value='0' />"+prefs.getMsg("A cross between a cabbage and a turnip")+"<br />";
    data13 += "<input type='radio' name='data13' value='5' />"+prefs.getMsg("A cross between a parsnip and a beetroot")+"<br />";
    data13 += "<input type='radio' name='data13' value='0' />"+prefs.getMsg("A cross between fennel and carrots")+"<br /><br />";
	//htmlout += data6+ "<br />";
	
	var data14 = "<div style='width:100%;background-color:#59a9c3;color:#FFFFFF;padding-left:10px;font-size:11px;padding-top:2px;padding-bottom:2px;'>"+prefs.getMsg("Which animal is not a Chinese year?")+"</div>";
	data14 += "<input type='radio' name='data14' value='0' />"+prefs.getMsg("Crow")+"<br />";
    data14 += "<input type='radio' name='data14' value='5' />"+prefs.getMsg("OX")+"<br />";
    data14 += "<input type='radio' name='data14' value='0' />"+prefs.getMsg("Hare")+"<br /><br />";
	//htmlout += data6+ "<br />";
	
	var data15 = "<div style='width:100%;background-color:#59a9c3;color:#FFFFFF;padding-left:10px;font-size:11px;padding-top:2px;padding-bottom:2px;'>"+prefs.getMsg("How many feet apart are the two wickets on a cricket pitch?")+"</div>";
	data15 += "<input type='radio' name='data15' value='0' />"+prefs.getMsg("15 yards")+"<br />";
    data15 += "<input type='radio' name='data15' value='5' />"+prefs.getMsg("22 yards")+"<br />";
    data15 += "<input type='radio' name='data15' value='0' />"+prefs.getMsg("25 yards")+"<br /><br />";
	//htmlout += data6+ "<br />";
	
	var data16 = "<div style='width:100%;background-color:#59a9c3;color:#FFFFFF;padding-left:10px;font-size:11px;padding-top:2px;padding-bottom:2px;'>"+prefs.getMsg("The oldest Indian language is:")+"</div>";
	data16 += "<input type='radio' name='data16' value='0' />"+prefs.getMsg("Hindi")+"<br />";
    data16 += "<input type='radio' name='data16' value='5' />"+prefs.getMsg("Telugu")+"<br />";
    data16 += "<input type='radio' name='data16' value='0' />"+prefs.getMsg("Tamil")+"<br /><br />";
	//htmlout += data6+ "<br />";
	
	var data17 = "<div style='width:100%;background-color:#59a9c3;color:#FFFFFF;padding-left:10px;font-size:11px;padding-top:2px;padding-bottom:2px;'>"+prefs.getMsg("English language having nore than ?? words:")+"</div>";
	data17 += "<input type='radio' name='data17' value='0' />"+prefs.getMsg("4,50,000")+"<br />";
    data17 += "<input type='radio' name='data17' value='5' />"+prefs.getMsg("45,000")+"<br />";
    data17 += "<input type='radio' name='data17' value='0' />"+prefs.getMsg("4,500")+"<br /><br />";
	//htmlout += data6+ "<br />";
	
	var data18 = "<div style='width:100%;background-color:#59a9c3;color:#FFFFFF;padding-left:10px;font-size:11px;padding-top:2px;padding-bottom:2px;'>"+prefs.getMsg("The play 'Shakuntala' was written by:")+"</div>";
	data18 += "<input type='radio' name='data18' value='0' />"+prefs.getMsg("Kalidas")+"<br />";
    data18 += "<input type='radio' name='data18' value='5' />"+prefs.getMsg("Tulsidas")+"<br />";
    data18 += "<input type='radio' name='data18' value='0' />"+prefs.getMsg("Swami Dayanand")+"<br /><br />";
	//htmlout += data6+ "<br />";
	
	var data19 = "<div style='width:100%;background-color:#59a9c3;color:#FFFFFF;padding-left:10px;font-size:11px;padding-top:2px;padding-bottom:2px;'>"+prefs.getMsg("Who discovered Australia?")+"</div>";
	data19 += "<input type='radio' name='data19' value='0' />"+prefs.getMsg("Eric the Red")+"<br />";
    data19 += "<input type='radio' name='data19' value='5' />"+prefs.getMsg("Leif Ericsson")+"<br />";
    data19 += "<input type='radio' name='data19' value='0' />"+prefs.getMsg("William Janszoom")+"<br /><br />";
		
	var data20 = "<div style='width:100%;background-color:#59a9c3;color:#FFFFFF;padding-left:10px;font-size:11px;padding-top:2px;padding-bottom:2px;'>"+prefs.getMsg("Who located magnetic pole?")+"</div>";
	data20 += "<input type='radio' name='data20' value='0' />"+prefs.getMsg("Sir James Clark")+"<br />";
    data20 += "<input type='radio' name='data20' value='5' />"+prefs.getMsg("Rear Admiral")+"<br />";
    data20 += "<input type='radio' name='data20' value='0' />"+prefs.getMsg("Sir John Ross")+"<br /><br />";
		
		
	for (var i = 0; i < 10 ; i++) 
	  { 
	  	if(i > 4)
		{
	  		if(myNumArray[i] == 1)
				table2html += "<tr><td style='font-size:11px;'>"+data1+ "</td></tr>";	
			else if(myNumArray[i] == 2)
				table2html += "<tr><td style='font-size:11px;'>"+data2+ "</td></tr>";
			else if(myNumArray[i] == 3)
				table2html += "<tr><td style='font-size:11px;'>"+data3+ "</td></tr>";	
			else if(myNumArray[i] == 4)
				table2html += "<tr><td style='font-size:11px;'>"+data4+ "</td></tr>";
			else if(myNumArray[i] == 5)
				table2html += "<tr><td style='font-size:11px;'>"+data5+ "</td></tr>";	
			else if(myNumArray[i] == 6)
				table2html += "<tr><td style='font-size:11px;'>"+data6+ "</td></tr>";	
			else if(myNumArray[i] == 7)
				table2html += "<tr><td style='font-size:11px;'>"+data7+ "</td></tr>";	
			else if(myNumArray[i] == 8)
				table2html += "<tr><td style='font-size:11px;'>"+data8+ "</td></tr>";
			else if(myNumArray[i] == 9)
				table2html += "<tr><td style='font-size:11px;'>"+data9+ "</td></tr>";	
			else if(myNumArray[i] == 10)
				table2html += "<tr><td style='font-size:11px;'>"+data10+ "</td></tr>";
			else if(myNumArray[i] == 11)
				table2html += "<tr><td style='font-size:11px;'>"+data11+ "</td></tr>";	
			else if(myNumArray[i] == 12)
				table2html += "<tr><td style='font-size:11px;'>"+data12+ "</td></tr>";
			else if(myNumArray[i] == 13)
				table2html += "<tr><td style='font-size:11px;'>"+data13+ "</td></tr>";	
			else if(myNumArray[i] == 14)
				table2html += "<tr><td style='font-size:11px;'>"+data14+ "</td></tr>";
			else if(myNumArray[i] == 15)
				table2html += "<tr><td style='font-size:11px;'>"+data15+ "</td></tr>";
			else if(myNumArray[i] == 16)
				table2html += "<tr><td style='font-size:11px;'>"+data16+ "</td></tr>";
			else if(myNumArray[i] == 17)
				table2html += "<tr><td style='font-size:11px;'>"+data17+ "</td></tr>";
			else if(myNumArray[i] == 18)
				table2html += "<tr><td style='font-size:11px;'>"+data18+ "</td></tr>";	
			else if(myNumArray[i] == 19)
				table2html += "<tr><td style='font-size:11px;'>"+data19+ "</td></tr>";
			else if(myNumArray[i] == 20)
				table2html += "<tr><td style='font-size:11px;'>"+data20+ "</td></tr>";
		}
		else
		{
			if(myNumArray[i] == 1)
				table1html += "<tr><td style='font-size:11px;'>"+data1+ "</td></tr>";	
			else if(myNumArray[i] == 2)
				table1html += "<tr><td style='font-size:11px;'>"+data2+ "</td></tr>";
			else if(myNumArray[i] == 3)
				table1html += "<tr><td style='font-size:11px;'>"+data3+ "</td></tr>";	
			else if(myNumArray[i] == 4)
				table1html += "<tr><td style='font-size:11px;'>"+data4+ "</td></tr>";
			else if(myNumArray[i] == 5)
				table1html += "<tr><td style='font-size:11px;'>"+data5+ "</td></tr>";	
			else if(myNumArray[i] == 6)
				table1html += "<tr><td style='font-size:11px;'>"+data6+ "</td></tr>";	
			else if(myNumArray[i] == 7)
				table1html += "<tr><td style='font-size:11px;'>"+data7+ "</td></tr>";	
			else if(myNumArray[i] == 8)
				table1html += "<tr><td style='font-size:11px;'>"+data8+ "</td></tr>";
			else if(myNumArray[i] == 9)
				table1html += "<tr><td style='font-size:11px;'>"+data9+ "</td></tr>";	
			else if(myNumArray[i] == 10)
				table1html += "<tr><td style='font-size:11px;'>"+data10+ "</td></tr>";
			else if(myNumArray[i] == 11)
				table1html += "<tr><td style='font-size:11px;'>"+data11+ "</td></tr>";	
			else if(myNumArray[i] == 12)
				table1html += "<tr><td style='font-size:11px;'>"+data12+ "</td></tr>";
			else if(myNumArray[i] == 13)
				table1html += "<tr><td style='font-size:11px;'>"+data13+ "</td></tr>";	
			else if(myNumArray[i] == 14)
				table1html += "<tr><td style='font-size:11px;'>"+data14+ "</td></tr>";
			else if(myNumArray[i] == 15)
				table1html += "<tr><td style='font-size:11px;'>"+data15+ "</td></tr>";
			else if(myNumArray[i] == 16)
				table1html += "<tr><td style='font-size:11px;'>"+data16+ "</td></tr>";
			else if(myNumArray[i] == 17)
				table1html += "<tr><td style='font-size:11px;'>"+data17+ "</td></tr>";
			else if(myNumArray[i] == 18)
				table1html += "<tr><td style='font-size:11px;'>"+data18+ "</td></tr>";	
			else if(myNumArray[i] == 19)
				table1html += "<tr><td style='font-size:11px;'>"+data19+ "</td></tr>";
			else if(myNumArray[i] == 20)
				table1html += "<tr><td style='font-size:11px;'>"+data20+ "</td></tr>";
		}	  				
	  }	
	  table1html += "</table>";
	  table2html += "</table>";
	  htmlout += "<tr><td style='width:50%;'>"+table1html+"</td><td>"+table2html+"</td></tr></table>";
      div.innerHTML = htmlout;
   }

function init() 
{		
  loadFriends(); 
 populateMyAppData();
}
